package com.cloud.consumer;

import com.cloud.consumer.consumer.SimpleInput;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.Message;

/**
 * @Author: TongRui乀
 * @Date: 2019/10/29 11:29
 * @description：
 */
@Slf4j
@EnableBinding(SimpleInput.class)
public class SimpleConsumer {


    @StreamListener(SimpleInput.IN_PUT)
    public void handle(String message){

      log.info(message);

//      throw new RuntimeException("test error");
    }


    /**
     *  Application异常： 自定义异常管道
     * @param message
     */
   /* @ServiceActivator(inputChannel = SimpleInput.IN_PUT + ".simpleConsumer.error")
    public void handleEerror(Message<?> message){

        log.error(message.toString());

    }*/


    /**
     *  Application异常： 全局异常管道
     * @param message
     */
    @StreamListener("errorChannel")
    public void error(Message<?> message) {
        System.out.println("Handling ERROR: " + message);
    }


     @ServiceActivator(inputChannel = SimpleInput.IN_PUT + ".simpleConsumer.dlq")
    public void handleEerror(String message){

        log.error(message);

    }



}
